package com.sulent.frame.file.utils;

import io.minio.CreateMultipartUploadResponse;
import io.minio.S3Base;

import java.io.File;

/**
 * @ClassName SubS3BaseDemo
 * @Description: TODO
 * @Author Submerge.
 * @Since 2024/2/4 10:18
 * @Version 1.0
 */
public class SubS3BaseDemo {

    public static void main(String[] args) {
/*        String endpoint= "http://172.16.0.16:9000/";
        String accessKey="rcmL8t0EfcmaGrEQ";
        String secretKey="0CDZzmRFlqLaRnoufn177wycXlin3lt1";
        String bucketName="ai-model";

        File file = new File(filePath);
        long contentLength = file.length();
        long partSize = 5 * 1024 * 1024; // Set part size to 5 MB.

        try {

            FileShardingServer shardingServer = new FileShardingServer(endpoint,null,true,);
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .withRegion(clientRegion)
                    .withCredentials(new ProfileCredentialsProvider())
                    .build();

            // Create a list of ETag objects. You retrieve ETags for each object part uploaded,
            // then, after each individual part has been uploaded, pass the list of ETags to
            // the request to complete the upload.
            List<PartETag> partETags = new ArrayList<PartETag>();


            CreateMultipartUploadResponse multipartUpload = fileShardingServer.createMultipartUpload(bucketName, null, filePath, null, null);

            // Upload the file parts.
            long filePosition = 0;
            for (int i = 1; filePosition < contentLength; i++) {
                // Because the last part could be less than 5 MB, adjust the part size as needed.
                partSize = Math.min(partSize, (contentLength - filePosition));

                // Create the request to upload a part.
                UploadPartRequest uploadRequest = new UploadPartRequest()
                        .withBucketName(bucketName)
                        .withKey(keyName)
                        .withUploadId(initResponse.getUploadId())
                        .withPartNumber(i)
                        .withFileOffset(filePosition)
                        .withFile(file)
                        .withPartSize(partSize);

                // Upload the part and add the response's ETag to our list.
                UploadPartResult uploadResult = s3Client.uploadPart(uploadRequest);
                partETags.add(uploadResult.getPartETag());

                filePosition += partSize;
            }

            // Complete the multipart upload.
            CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucketName, keyName,
                    initResponse.getUploadId(), partETags);
            s3Client.completeMultipartUpload(compRequest);
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }*/

    }
}
